package com.yanqu.road.entity.autodata;

import java.sql.Types;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class SqlTypeHelper {
    private static Map<Class<?>, Integer> sqlTypeMap = new HashMap<>();

    static {
        sqlTypeMap.put(String.class, Types.VARCHAR);
        sqlTypeMap.put(int.class, Types.INTEGER);
        sqlTypeMap.put(Integer.class, Types.INTEGER);
        sqlTypeMap.put(long.class, Types.BIGINT);
        sqlTypeMap.put(Long.class, Types.BIGINT);
        sqlTypeMap.put(boolean.class, Types.BOOLEAN);
        sqlTypeMap.put(Date.class, Types.DATE);
    }

    public static Integer getSqlType(Class<?> clazz) {
        Integer type = sqlTypeMap.get(clazz);
        return type;
    }

    public static boolean isNeedJsonCast(Class<?> clazz) {
        Integer type = sqlTypeMap.get(clazz);
        return type == null;
    }
}
